﻿@model dynamic
@{ViewBag.Title = "短信留言"; }
@helper listview(IQueryable<aspnet_Users> rl)
    {
        foreach (var item in rl)
        {
    <input name="recivers" checked="checked" type="checkbox" 
            id = "recu_@(item.UserId.ToString("N"))"
            value="@(item.UserId)"
            title = "@(item.MobileAlias)" />
    <label for='recu_@(item.UserId.ToString("N"))'>@item.UserName</label><text>
    </text>
        }
}
@{
    var rl = ViewBag.RecuperUsers as IQueryable<aspnet_Users>;
}
@if (null != rl)
{
    @listview(rl)
}
else
{
    <fieldset>
        <legend>
            <div class="catalog-title">
                短信留言
            </div>
        </legend>
        @using (Ajax.BeginForm(new AjaxOptions()
    {
        LoadingElementId = "OnLoadingSpan",
        UpdateTargetId = ViewBag.utid,
        InsertionMode = InsertionMode.Replace,
        HttpMethod = "Post"
        ,
        OnSuccess = "alert('操作成功')"
        ,
        OnFailure = "OnSiteError"
        ,
        OnBegin = "$('#submit').fadeOut(500)"
        ,
        OnComplete = "$('#submit').fadeIn(1000)"
    }))
        {
            @Html.ValidationSummary(true)

            <table width="100%">
                <tr>
                    <td width="40%">
                        @Ajax.ActionLink("[添加患者]", "SentSmsImportRecuper", new { ID = Guid.Empty, utid = "listview" }, new AjaxOptions() { LoadingElementId = "OnLoadingSpan", UpdateTargetId = "dialogbox", OnComplete = "showDialog('添加患者');", HttpMethod = "Get", InsertionMode = InsertionMode.Replace, OnFailure = "OnSiteError" })
                        <i>点击[添加患者]链接以添加更多短信接收者</i>
                    </td>
                    <td valign="middle" align="left">
                        请输入短信内容，或使用模板<br />
                        <nobr> @Html.DropDownList("SmsTextList", new SelectList(ViewBag.Templates, "SmsText", "SmsText"), new { id = "smsDDL", style = "width:80%" })
                                        <input id="btnImport" class="ui-button ui-widget ui-state-default ui-corner-all"
                        type="button" value="导入" onclick="$('#txtmessage').val($('#txtmessage').val()+$('#smsDDL').val());$('#smsTextCount').text('字数：'+$('#txtmessage').val().length.toString())" />
                </nobr>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div id="listview">
                        </div>
                    </td>
                    <td>
                        @Html.TextArea("txtmessage", string.Empty, 10, 80, null)
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        @Helpers.SubmitButton("发送")
                        <span id="smsTextCount"></span>
                    </td>
                </tr>
            </table>}
    </fieldset>
    <script type="text/javascript">
        $(document).ready(function () {
            var text = $("#txtmessage").val();
            var counter = text.length;
            if (counter != 0) {
                $("#smsTextCount").text("字数：" + counter.toString());
            }
            else {
                $("#smsTextCount").text("");
            }
            $("#txtmessage").keyup(function () {
                var text = $("#txtmessage").val();
                var counter = text.length;
                if (counter != 0) {
                    $("#smsTextCount").text("字数：" + counter.toString());
                }
                else {
                    $("#smsTextCount").text("");
                }
            });
        });

    </script>

}
